package orbitPrototype.gui;

import orbitPrototype.loaders.XMLLoader;
import orbitPrototype.objects.Sprite;

/**
 * Description:	Three state sprite button.
 * @author Drapan
 *
 */
public class GUISpriteButton extends GUISimpleButton
{
	private Sprite _defaultState = null;
	private Sprite _hoverState = null;
	private Sprite _downState = null;
	
	public GUISpriteButton(int x, int y, String actionLabel, Object actionGlobal, String spriteUniqueName, boolean hover, boolean down, GUIWindow parentWindow)
	{
		super(x, y, 
				Integer.parseInt(XMLLoader.getElementValue("width", XMLLoader.getXMLElementByUniqueName("spriteLookup_gui", spriteUniqueName))),
				Integer.parseInt(XMLLoader.getElementValue("height", XMLLoader.getXMLElementByUniqueName("spriteLookup_gui", spriteUniqueName))), 
				actionLabel, actionGlobal, parentWindow);
		
		init(spriteUniqueName, hover, down);
	}
	
	private void init(String spriteUniqueName, boolean hover, boolean down)
	{
		_defaultState = new Sprite(0, 0, "gui", spriteUniqueName);
		this.addChild(_defaultState);
		
		if(hover)
		{
			_hoverState = new Sprite(0, 0, "gui", spriteUniqueName + "_hover");
			this.addChild(_hoverState);
			_hoverState.setVisible(false);
		}
		if(down)
		{
			_downState =  new Sprite(0, 0, "gui", spriteUniqueName + "_down");
			this.addChild(_downState);
			_downState.setVisible(false);
		}
	}
	
	@Override
	public void hoverState()
	{
		if(_hoverState != null)
		{
			this.makeOnlyVisible(_hoverState);
		}
	}

	@Override
	public void downState()
	{
		if(_downState != null)
		{
			this.makeOnlyVisible(_downState);
		}
	}
	
	@Override
	public void defaultState()
	{
		this.makeOnlyVisible(_defaultState);
	}
}
